package eclipse.server.threadpool;
import eclipse.server.Database;
import eclipse.util.*;
/** 
 * The NetProcessThread handles all net functions that Clients may have requested.
 */
public class NetProcessThread extends ThreadedTimer 
{
	String netMsg;
	int Index;
	public NetProcessThread(int Index)
	{
		this.Index = Index;
		setName("Player" + Index + ": Net Process Thread");
		setEnabled(true);
		setInterval(Database.NETPROCESSINTERVAL);
		start();		
	}
	public void tick()
	{
		if(Database.client[Index] != null)
		{				
			if(Database.client[Index].isConnected())
			{					
				netMsg = Database.client[Index].getString();
				if(netMsg != null)
					eclipse.lib.sockets.ServerDataHandle.process(Index, netMsg);
				else
				{
					try
					{
						Database.client[Index].close();											
					}		
					catch(Exception e){}//dump errors
					{
						
					}
					Database.client[Index] = null;
					setRunStatus(false);		
				}
			}
		}
	}
}
